// pages/xiangce/xiangce.js
let app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgWidth: 0,
    imgHeight: 0,
    pics:[],
    picslength:1,
  },
  onClick(event) {
    new Promise(function(resolve){
      wx.showToast({
        title: '图片加载中！',
       icon:"loading",
       duration:1000
      });
      resolve();
    }).then(this.getpic(event.detail.title))
      
  },
  onLoad: function (options) {

  },
  onReady: function () {
    app.globalData.openid=wx.getStorageSync('openid');
    console.log(app.globalData.openid);
    this.getpic("人像");
  },
  getpic(root)
  {
    let that=this;
    that.setData({
      pics:[]
    });
    wx.request({
      url:app.globalData.url+'/getuserpic', 
      header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      data: {
          openid:app.globalData.openid,
          leixing:root
       },
       method: 'post',
       success: function (res) {
           if(res.data.length==0)
           {
             that.setData({
               picslength:0
             });
           }
           else
           {
            that.setData({
              pics:res.data,
              picslength:1
            })
           }
       },
       fail:function(err){//请求失败之后要做什么
          console.log('请求失败')
          }
          
  })
  },
  //预览图片
  PreviewImg(e){
    let index=e.target.dataset.index
    wx.previewImage({
      current:this.data.pics[index],
      urls:this.data.pics,
    })
    }
})